home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / source / scaledemo.lha / ScaleDemo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-01  |  3.5 KB  |  142 lines

  1. ;/* ScaleDemo.c - Execute me to compile me with SAS C 5.10
  2. LC -b1 -cfistq -v -y -j73 ScaleDemo.c
  3. Blink FROM LIB:c.o,ScaleDemo.o,bitmap.o TO ScaleDemo LIBRARY LIB:LC.lib,LIB:Amiga.lib
  4. quit
  5. */
  6.  
  7. #define INTUI_V36_NAMES_ONLY
  8.  
  9. #include <exec/types.h>
  10. #include <exec/memory.h>
  11. #include <intuition/intuition.h>
  12. #include <Graphics/Scale.h>
  13.  
  14. #include <Proto/Exec.h>
  15. #include <Proto/graphics.h>
  16. #include <Proto/intuition.h>
  17.  
  18. UBYTE vers[] = "$VER: ScaleDemo 37.2";
  19.  
  20. extern struct BitMap SourceBM;  // Pointer to the self contained BitMap module;
  21.  
  22. struct Library    *GfxBase;
  23. struct Library    *IntuitionBase;
  24.  
  25. struct Window    *Win;    // window pointer
  26.  
  27. // Prototypes
  28. VOID doDrawStuff(void);
  29. VOID doMsgLoop(void);
  30. VOID handleWindow(struct Screen *myscreen);
  31.  
  32. VOID _main(char *line)
  33. {
  34.  register struct Screen *screen;
  35.  
  36.  if(IntuitionBase=OpenLibrary("intuition.library",37)){
  37.     if(GfxBase=OpenLibrary("graphics.library",33)){
  38.     if(NULL!=(screen=LockPubScreen(NULL))){
  39.         handleWindow(screen);
  40.         UnlockPubScreen(NULL,screen);
  41.     }
  42.     CloseLibrary(GfxBase);
  43.     }
  44.     CloseLibrary(IntuitionBase);
  45.  }
  46. }
  47.  
  48. VOID handleWindow(struct Screen *screen)
  49. {
  50.  if(!(Win=OpenWindowTags(NULL,
  51.     WA_Width    ,320,
  52.     WA_Height    ,100,
  53.     WA_MinWidth    ,60,
  54.     WA_MinHeight    ,40,
  55.     WA_MaxWidth    ,-1,
  56.     WA_MaxHeight    ,-1,
  57.     WA_IDCMP, IDCMP_NEWSIZE|IDCMP_CLOSEWINDOW,
  58.     WA_Flags, WFLG_SIZEGADGET | WFLG_DRAGBAR | WFLG_DEPTHGADGET |
  59.         WFLG_CLOSEGADGET | WFLG_SIMPLE_REFRESH,
  60.     WA_Title, vers+6, // take title from version string
  61.     WA_PubScreen, screen,
  62.     TAG_DONE))) return;
  63.  doDrawStuff();
  64.  doMsgLoop();
  65.  CloseWindow(Win);
  66. }
  67.  
  68. VOID doDrawStuff()
  69. {
  70.  int SrcfX=384;    // Source factors
  71.  int SrcfY=200;
  72.  int DestfX;    // Destination factors
  73.  int DestfY;
  74.  int topborder;
  75.  int InnerWidth;
  76.  int InnerHeight;
  77.  struct BitScaleArgs bsa;
  78.  
  79.  Forbid(); // Forbid so the user doesn't size the window while we draw.
  80.  
  81. // Determine window's inner dimensions...
  82.  topborder=Win->WScreen->WBorTop+(Win->WScreen->Font->ta_YSize+1);
  83.  InnerWidth=Win->Width-Win->BorderLeft-Win->BorderRight;
  84.  InnerHeight=Win->Height-topborder-Win->BorderBottom;
  85.  
  86.  bsa.bsa_SrcX=0;    // Offsets should be 0 to read the whole source
  87.  bsa.bsa_SrcY=0;
  88.  bsa.bsa_SrcWidth=384;    // Full width of source bitmap
  89.  bsa.bsa_SrcHeight=200; // Full height of source bitmap
  90.  
  91.  bsa.bsa_DestX=Win->LeftEdge+Win->BorderLeft; // Offsets to draw into dest
  92.  bsa.bsa_DestY=Win->TopEdge+Win->BorderTop;
  93.  bsa.bsa_DestWidth=0; // Dest width & height seem to be ignored;
  94.  bsa.bsa_DestHeight=0;
  95.  
  96. /*
  97. * Examples for determining factors:
  98. *    If dest was 1, and source was 4, it would be 1/4 (exactly one quarter)
  99. *    If dest was 2, and source was 1, it would be 2/1 (exactly doubled)
  100. *
  101. * Here we simplify it by using the source size as the source factor, so...
  102. * ScalerDiv(384,InnerWidth,384) = scale by InnerWidth/384'ths
  103. */
  104.  
  105.  DestfX=ScalerDiv(SrcfX,InnerWidth ,384);
  106.  DestfY=ScalerDiv(SrcfY,InnerHeight,200);
  107.  
  108.  bsa.bsa_XSrcFactor=SrcfX;
  109.  bsa.bsa_YSrcFactor=SrcfY;
  110.  bsa.bsa_XDestFactor=DestfX;
  111.  bsa.bsa_YDestFactor=DestfY;
  112.  
  113.  bsa.bsa_SrcBitMap=&SourceBM;
  114. // We are drawing directly to the Workbench screen's BitMap.  Not very nice, eh?
  115.  bsa.bsa_DestBitMap=&Win->WScreen->BitMap;
  116.  
  117.  bsa.bsa_Flags=0;
  118.  BitMapScale(&bsa); // Do it!
  119.  Permit();
  120. }
  121.  
  122. VOID doMsgLoop()
  123. {
  124.  register struct IntuiMessage *msg;
  125.  register WORD flag=TRUE;
  126.  
  127.  while(flag){
  128.     WaitPort(Win->UserPort);
  129.     while(msg=(struct IntuiMessage *)GetMsg(Win->UserPort)){
  130.     switch(msg->Class){
  131.         case IDCMP_CLOSEWINDOW:
  132.         flag=FALSE;
  133.         break;
  134.         case IDCMP_NEWSIZE:
  135.         doDrawStuff();
  136.         break;
  137.     }
  138.     ReplyMsg((struct Message *)msg);
  139.     }
  140.  }
  141. }
  142.